package com.loan.web.pdf.controller.create;

import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.AjaxResult;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.common.utils.poi.ExcelUtil;
import com.loan.system.create.domain.AssistPdfSearchNhBase;
import com.loan.system.create.service.IAssistPdfSearchNhBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * NH数据Controller
 *
 * @author Sophia
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/system/nhSearch")
public class AssistPdfSearchNhBaseController extends BaseController {
    @Autowired
    private IAssistPdfSearchNhBaseService assistPdfSearchNhBaseService;

    /**
     * 查询NH数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:nhSearch:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssistPdfSearchNhBase assistPdfSearchNhBase) {
        startPage();
        List<AssistPdfSearchNhBase> list = assistPdfSearchNhBaseService.selectAssistPdfSearchNhBaseList(assistPdfSearchNhBase);
        return getDataTable(list);
    }

    /**
     * 导出NH数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:nhSearch:export')")
    @Log(title = "NH数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssistPdfSearchNhBase assistPdfSearchNhBase) {
        List<AssistPdfSearchNhBase> list = assistPdfSearchNhBaseService.selectAssistPdfSearchNhBaseList(assistPdfSearchNhBase);
        ExcelUtil<AssistPdfSearchNhBase> util = new ExcelUtil<AssistPdfSearchNhBase>(AssistPdfSearchNhBase.class);
        util.exportExcel(response, list, "NH数据数据");
    }

    /**
     * 获取NH数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:nhSearch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(assistPdfSearchNhBaseService.selectAssistPdfSearchNhBaseById(id));
    }

    /**
     * 新增NH数据
     */
    @PreAuthorize("@ss.hasPermi('system:nhSearch:add')")
    @Log(title = "NH数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssistPdfSearchNhBase assistPdfSearchNhBase) {
        return toAjax(assistPdfSearchNhBaseService.insertAssistPdfSearchNhBase(assistPdfSearchNhBase));
    }

    /**
     * 修改NH数据
     */
    @PreAuthorize("@ss.hasPermi('system:nhSearch:edit')")
    @Log(title = "NH数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssistPdfSearchNhBase assistPdfSearchNhBase) {
        return toAjax(assistPdfSearchNhBaseService.updateAssistPdfSearchNhBase(assistPdfSearchNhBase));
    }

    /**
     * 删除NH数据
     */
    @PreAuthorize("@ss.hasPermi('system:nhSearch:remove')")
    @Log(title = "NH数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(assistPdfSearchNhBaseService.deleteAssistPdfSearchNhBaseByIds(ids));
    }
}
